<template>
    <div class="management-less">
        <el-form :inline="true" :model="formInline1" class="demo-form-inline t-a-l">
            <el-form-item label="姓名：">
                <el-input v-model="formInline1.entity.name" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="手机号：">
                <el-input v-model="formInline1.entity.phone" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报考类型">
                <el-select v-model="formInline1.entity.subjectsId" placeholder="全部">
                    <el-option label="全部" value=""></el-option>
                    <el-option v-for="item in subList" :key="item.id" :label="item.chName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报考状态">
                <el-select v-model="formInline1.entity.status" placeholder="全部">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="未审核" value="0"></el-option>
                    <el-option label="机构审核" value="1"></el-option>
                    <el-option label="协会审核" value="2"></el-option>
                    <el-option label="已缴费" value="3"></el-option>
                    <el-option label="已排场" value="4"></el-option>
                    <el-option label="已通过" value="5"></el-option>
                    <el-option label="未通过" value="6"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="list">查询</el-button>
            </el-form-item>
        </el-form>
        <div class="border-s my-test">
            <el-table :data="tableData" style="width: 100%" :border="false">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="phone" label="电话"></el-table-column>
                <el-table-column prop="sex" label="性别" :formatter="sexFormatter"></el-table-column>
                <el-table-column prop="corporation" label="所属单位"></el-table-column>
                <el-table-column prop="subjectsName" label="报考类型"></el-table-column>
                <el-table-column prop="examinationName" label="考场号"></el-table-column>
                <el-table-column prop="seat" label="座位号"></el-table-column>
                <el-table-column prop="status" label="考试状态" :formatter="statusFormatter"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.status == 0" @click="confirm(scope.row),rejected.reject=true,rejected.id = scope.row.id" type="text" size="medium" class="button-my-test">通过</el-button>
                        <el-button v-if="scope.row.status == 0" @click="centerDialogVisible = true,rejected.reject=false,rejected.id = scope.row.id" type="text" size="medium" class="button-my-test">驳回</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-dialog title="驳回" class="rejected" :visible.sync="centerDialogVisible" width="30%" center>
            <el-form ref="form" :model="rejected" label-width="80px">
                <el-form-item label="请输入">
                    <el-input type="textarea" placeholder="驳回原因..." v-model="rejected.reason"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="medium" @click="centerDialogVisible = false">取 消</el-button>
                <el-button size="medium" type="primary" @click="centerDialogVisible = false,handleClick()">确 定</el-button>
            </span>
        </el-dialog>
        <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :page-size="formInline1.pageable.size"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            @size-change="pageFy"
            :total="total">
            </el-pagination>
    </div>
</template>
<script>
import apiHttp from '../../../api/index.js'
export default {
    data(){
        return{
            formInline: {
                user: '',
                region: '',
                phone:''
            },
            formInline1: {
                entity:{
                    name:'',
                    phone:'',
                    status:null
                },
                pageable:{
                    current:1,
                    size:10
                },
            },
            tableData:[],
            centerDialogVisible:false,
            rejected:{
                reason:'',
            },
            total:0,
            subList:[]
        }
    },
    mounted(){
        this.list()
        this.subjectList()
    },
    methods:{
        // 列表
        list(){
            apiHttp.apiIndex.orgOrderList(this.formInline1).then(resp=>{
                if(resp.code == 0){
                    this.tableData = resp.data.records
                    this.total = Number(resp.data.total)
                }
            })
        },
        // 获取科目列表
        subjectList(){
            apiHttp.apiIndex.subjects().then(resp=>{
                if(resp.code == 0){
                    this.subList = resp.data
                }
            })
        },
        // 报考状态分拣
        statusFormatter(val){
            if(val.status == 0){
                return '未审核'
            }else if(val.status == 1 || val.status == 2){
                return '审核通过，等待付费'
            }else if(val.status == 3){
                return '报名成功，等待考试'
            }else if(val.status == 4){
                return '已分配考场号'
            }else if(val.status == 5){
                return '已通过'
            }else if(val.status == 6){
                return '未通过'
            }else if(val.status == 7){
                return '机构驳回'
            }else if(val.status == 8){
                return '协会驳回'
            }
        },
        // 性别过滤器
        sexFormatter(row){
            return row.sex == 0 ? '女' : '男'
        },
        // 分页
        handleCurrentChange(val){
            this.formInline1.pageable.current = val
            this.list()
        },
        pageFy(val){
            this.formInline1.pageable.size = val
            this.list()
        },
        // 驳回 + 通过
        handleClick() {
            apiHttp.apiIndex.orgOrderAudit(this.rejected).then(resp=>{
                if(resp.code == 0){
                    this.$message({
                        type: 'success',
                        message: '成功!'
                    })
                    this.list()
                }
            })
        },
        // 通过
        confirm() {
            let self = this
            this.$confirm('确认通过?', '', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                center:'true'
            }).then(() => {
                self.handleClick()
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });          
            });
      }
    }
}
</script>
<style lang="less">
.management-less{
    .el-form{
        .el-form-item{
            .el-form-item__content{
                .el-button--primary{
                    background-color: #5d2805;
                    border-color: #5d2805;
                }
            }
        }
    }
    .el-table th{
        color: #fff;
        background-color: #5d2805;
    }
    .el-table td, .el-table th{
        text-align: center;
        font-size: 16px;
    }
    .rejected{
        .el-dialog__body{
            padding: 25px 25px 10px;
            .el-form-item__label{
                display: none;
            }
            .el-form-item__content{
                margin-left: 0 !important;
            }
        }
        .el-dialog__footer{
            .el-button--primary{
                background-color: #5d2805;
                border-color: #5d2805;
            }
            .el-button--default:hover{
                background-color: #e4d7cf;
                border-color: #e4d7cf;
                color: #5d2805;
            }
        }
        .el-textarea__inner{
            min-height: 100px !important;
        }
    }
}
.el-message-box__message{
    font-size: 18px;
}
</style>

